package main.java.single;

// 懒汉式单例
public class LazyMan01 {
    //构造器私有
    private LazyMan01(){

    }

    private static LazyMan01 lazyMan;
    //多线程情况下 会存在问题 解决了多线程下的问题
    public static LazyMan01 getInstance(){
        if(lazyMan == null){
            synchronized (LazyMan01.class){
                if (lazyMan == null){
                    //还有问题 不是原子性操作
                    lazyMan = new LazyMan01();
                }
            }
        }
        return lazyMan;
    }
}
